import { s_getcommontableinfo, s_getPurchaseInfo, status2text } from "@/services/basis";
import { ProCard, ProColumns, ProTable } from "@ant-design/pro-components";
import { Button, Space, Tag ,Image} from "antd";
import { useState } from "react";

const App:React.FC=()=>{
    const [total,setTotal]=useState(0);
    interface DataType{
//         x_id,org_id,vouch_code,vendor_id,vouch_status,operate_time,
// material_id,userdefine_name,quantity,deliverdate,
// code,name,invstd,invstd2,munit_name,
// org_name,vendor_name,operater_name,
// quantity_deliver,quantity_reback,quantity_stockin,progress_stockin
cate_name?:string,quantity_current?:number,
x_id?:number,org_id?:number,vouch_code?:string,vendor_id?:number,vouch_status?:number,operate_time?:string,
material_id?:number,userdefine_name?:string,quantity?:number,deliverdate?:string,
code?:string,name?:string,invstd?:string,invstd2?:string,munit_name?:string,
org_name?:string,vendor_name?:string,operater_name?:string,pic?:string,quantity_arrive?:number,
quantity_deliver?:number,quantity_reback?:number,quantity_stockin?:number,progress_stockin?:number
    };

 const columns:ProColumns<DataType>[]=[
        {dataIndex:'pic',title:'图片' ,editable:false,search:false,width:80,
          //     render:(text)=>{
          //         var pic=text=="-"||text==undefined?"":"/basis_api/file/get?filename="+text;
          //         return <Image src={pic}  
          //                style={{width:50,height:50}} alt='无' />
          //    },
          //  },
             render:(text,record,index,k)=>{
                         var pic="/basis_api/file/get2?filename="+record.code;
                         return   <Image src={pic}  style={{width:50,height:50}} alt='无' />
          }},
        {dataIndex:'vouch_code',title:'采购单号',width:100},
        {dataIndex:'vendor_name',title:'供应商',width:100},
        {dataIndex:'cate_name',title:'商品类别',width:100},
        {dataIndex:'code',title:'SKU编码',width:100,},
        {dataIndex:'name',title:'商品名称',width:200},
        {dataIndex:'invstd',title:'包装规格',search:false,width:200},
        {dataIndex:'invstd2',title:'型号',search:false,},
        // {dataIndex:'userdefine_name',title:'自定义项'},
        {dataIndex:'munit_name',title:'计量单位',search:false,},
        {dataIndex:'quantity',title:'采购数量',search:false,},
        {dataIndex:'quantity_arrive',title:'到货数量',search:false,},
        {dataIndex:'quantity_stockin',title:'入库数量',search:false,},
        {dataIndex:'progress_stockin',title:'入库比例',valueType:'progress',width:180,search:false,
           renderText(text, record, index, action) {
             return Math.floor((record.quantity_stockin?record.quantity_stockin:0)/(record.quantity?record.quantity:1)*100)
             
           },
        },
        // {dataIndex:'quantity_reback',title:'退货数量',search:false,},
        {dataIndex:'quantity_current',title:'库存量',search:false,},
        
        {dataIndex:'deliverdate',title:'需求日期',valueType:'date',search:false,},
        // {dataIndex:'status',title:'进度',search:false,
        //     render:(text:any)=>text.indexOf('延')>=0?<Tag color='red' style={{width:60}}>{text}</Tag>:text,
        // },
        // {dataIndex:'org_name',title:'采购部门',search:false,},
        {dataIndex:'operater_name',title:'采购员',search:false,},
        {dataIndex:'vouch_status',title:'状态',valueType:'select',width:80,
                    valueEnum:{1:{text:'未审核'},5:{text:'已审核'},
                    6:{text:'已弃审'},2:{text:'关闭'},3:{text:'删除'},9:{text:'全部'}}
                }, 
    ];

    
    //==============================================================================================================
    return <>
      <ProCard title='采购进度跟踪' style={{height:'85vh',overflow:'auto'}}
        //  extra={<Space>
        //     <Button>查看采购齐套</Button>
        //     <Button>查看入库明细</Button>
             
        //  </Space>}
      >
          <ProTable<DataType>
             columns={columns}
            //  dataSource={tdata}
             search={{span:4}}
            //  rowSelection={{
            //     type:'checkbox'
            //  }}
             rowKey='id'
             options={false}
            //   request={async ()=>{
            //     // x_id,cate_id,id,source,fdata
            //     const x=await s_getcommontableinfo({x_id:1,cate_id:[],id:0,source:'v_purchase_order_progress',fdata:null});
            //     return {
            //         data:x.data[0],
            //         success:true,
            //     }
            //  }}
              // v_sale_order_main
             request={async (param)=>{
                  const x=await s_getPurchaseInfo({source:'v_purchase_order_progress',x_id:1,
                                               fdata:{id:0,param}});
                  setTotal(x.data[0][0].count);
                  return{
                         data:x.data[1],
                         success:true,
                         }
                 }}
          scroll={{y:'56vh'}}
                    pagination={{
                    showQuickJumper:true,
                    showSizeChanger:true,
                    defaultPageSize:10,
                    defaultCurrent:1,
                    total,
                  }}
          /> 
      </ProCard> 
    </>;
}

export default App;